home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / mac / hypercar / xfcn / spttool.cpt / Support Tools eXternals 1.2.5 / card_37379.txt < prev    next >
Text File  |  1990-11-13  |  6KB  |  187 lines

  1. -- card: 37379 from stack: in.5
  2. -- bmap block id: 36823
  3. -- flags: 0000
  4. -- background id: 3858
  5. -- name: MonitorCount
  6. ----- HyperTalk script -----
  7. on HideObjects
  8.   hide cd btn "Try It!"
  9. end HideObjects
  10.  
  11. on ShowObjects
  12.   show cd btn "Try It!"
  13. end ShowObjects
  14.  
  15.  
  16. -- part 1 (button)
  17. -- low flags: 00
  18. -- high flags: A002
  19. -- rect: left=82 top=185 right=219 bottom=175
  20. -- title width / last selected line: 0
  21. -- icon id / first selected line: 0 / 0
  22. -- text alignment: 1
  23. -- font id: 0
  24. -- text size: 12
  25. -- style flags: 8192
  26. -- line height: 16
  27. -- part name: Try it!
  28. ----- HyperTalk script -----
  29. on mouseUp
  30.   answer "This Mac has" && MonitorCount() && "monitors."
  31. end mouseUp
  32.  
  33.  
  34.  
  35.  
  36. -- part contents for background part 38
  37. ----- text -----
  38. 30/50
  39.  
  40. -- part contents for background part 20
  41. ----- text -----
  42.     This XFCN returns the number of active (useable) monitors attached to the Mac.
  43.  
  44.      Calling syntax : MonitorCount()
  45.  
  46.      Returns: the number of monitors.
  47.  
  48.  
  49. -- part contents for background part 42
  50. ----- text -----
  51. unit monitorCount;
  52. {}
  53. {monitorCount()}
  54. { Check and report the number of monitors currenty attached. }
  55. {}
  56. {}
  57. {   brought to you by:      Anup Murarka             Eric Carlson         }
  58. {                       ALINK:  SKEPTIC           ALINK:  cyNic   }
  59. {                                   CIS:  76004,3356         }
  60. {}
  61. {               We are part of the Support Tools Development Group,     }
  62. {               Apple Computer, Inc.      }
  63. {}
  64. {               please DO NOT contack Mac DTS for support of this code!    }
  65. {}
  66. {               please DO contact the authors for support of this code!     }
  67. {}
  68. {               Send comments, bug reports, requests to any of the above   }
  69. {               E-mail addresses or to:}
  70. {}
  71. {                           (one of us)                  }
  72. {                           Apple Computer, Inc.          }
  73. {                           900 E. Hamilton, Ave.          }
  74. {                           Campbell, CA   95008      }
  75. {                           M/S 72-L                     }
  76. {}
  77. {   Copyright:   ┬⌐ 1989, 1990 by Apple Computer, Inc., all rights reserved.     }
  78. {}
  79. { written by Eric Carlson                                        }
  80. { AppleLink:  cyNic                                              }
  81. { modification history                                                                                        }
  82. {          Date                  Initials                                    Comments                                   }
  83. {          ----              ------          --------------------------------------------------}
  84. {       9/1/89             ec            first written                                                               }
  85. {       6/6/90             ec            cleaned code, added comments                                         }
  86. {}
  87. interface
  88.  uses
  89.   HyperXCMD;
  90.  
  91.  procedure main (paramPtr: XCmdPtr);
  92.  
  93. implementation
  94.  
  95.  
  96.  function askedForHelp (paramPtr: XCmdPtr;
  97.        syntaxMsg: Str255;
  98.        copyRightMsg: Str255): boolean;
  99. {}
  100. {   check to see if the user sent a '?' or a '!' as }
  101. { the only parameter. if so we will respond with }
  102. { the calling syntax or the copyright/version info }
  103. { for this external }
  104. {}
  105.   var
  106.    firstStr: str255;
  107.  begin
  108.   askedForHelp := false;
  109.   if paramPtr^.paramCount = 1 then
  110.    begin
  111.     ZeroToPas(paramPtr, paramPtr^.params[1]^, firstStr);
  112.                     { what is the first param? }
  113.     if firstStr = '?' then
  114.      begin
  115.       paramPtr^.returnValue := PasToZero(paramPtr, syntaxMsg);
  116.       askedForHelp := true
  117.      end     { asked for help }
  118.     else if firstStr = '!' then
  119.      begin
  120.       paramPtr^.returnValue := PasToZero(paramPtr, copyRightMsg);
  121.       askedForHelp := true
  122.      end;    { asked for copyright info }
  123.    end;  { one parameter passed }
  124.  end;    { function }
  125.  
  126.  function NumberToString (paramPtr: XCmdPtr;
  127.        num: LONGINT): Str255;
  128. { use the toolbox call rather than HC's }
  129.   var
  130.    tempStr: str255;
  131.  begin
  132.   NumToString(num, tempStr);
  133.   NumberToString := tempStr;
  134.  end;
  135.  
  136.  procedure monitorCount (paramPtr: XCmdPtr);
  137.   const
  138.    UTableBase = $11C;
  139.    screenActive = 15;               { 1 if in use }
  140.  
  141.   var
  142.    currGDevice: GDHandle;
  143.    theSysEnv: SysEnvRec;
  144.    envErr: OSErr;
  145.    monitorNum: integer;
  146.    copyRtStr, syntaxStr: str255;
  147.  
  148.   function TestDeviceAttribute (gdh: GDHandle;
  149.        attribute: INTEGER): BOOLEAN;
  150.   inline
  151.    $AA2C;
  152.   function GetDeviceList: GDHandle;
  153.   inline
  154.    $AA29;
  155.   function GetGDevice: GDHandle;
  156.   inline
  157.    $AA32;
  158.  
  159.  begin
  160.   syntaxStr := 'monitorCount()';
  161.   copyRtStr := '┬⌐ 1989,1990 Apple Computer, Inc. v.1.0,  by Eric Carlson.';
  162.   if askedForHelp(paramPtr, syntaxStr, copyRtStr) then
  163.    exit(monitorCount);                         { just asking for help }
  164.  
  165.   monitorNum := 1;                                      { assume that we'll fond just one monitor }
  166.   envErr := SysEnvirons(1, theSysEnv);           { call sysEnvirons to see about color QD }
  167.   if envErr = noErr then
  168.    if theSysEnv.hasColorQD then         { only proceed if we have color QD }
  169.     begin
  170.      monitorNum := 0;
  171.      currGDevice := GetDeviceList;                   { grab the first gDevice in the list }
  172.      while (currGDevice <> nil) do                     { and step through the whole list }
  173.       begin
  174.        if TestDeviceAttribute(currGDevice, screenActive) then       { see if the screen is active }
  175.         monitorNum := monitorNum + 1;                 { another gDevice = another monitor }
  176.        currGDevice := currGDevice^^.gdNextGD;   { get the next one }
  177.       end;
  178.     end;
  179.  
  180.   paramPtr^.returnValue := PasToZero(paramPtr, NumberToString(paramPtr, monitorNum));
  181.  end;
  182.  
  183.  procedure main (paramPtr: XCmdPtr);
  184.  begin
  185.   monitorCount(paramPtr);
  186.  end;
  187. end.